package com.spt.msk.util;
import java.io.InputStream;
import java.util.Properties;

public class ConfigLoader {

    private final Properties properties = new Properties();

    public ConfigLoader(String configFileName) {
        try (InputStream input = getClass().getClassLoader().getResourceAsStream(configFileName)) {
            if (input == null) {
                throw new RuntimeException("找不到配置文件: " + configFileName);
            }
            properties.load(input);
        } catch (Exception e) {
            throw new RuntimeException("加载配置失败", e);
        }
    }

    public String get(String key) {
        return properties.getProperty(key);
    }

    public String get(String key, String defaultValue) {
        return properties.getProperty(key, defaultValue);
    }

    // 单例模式
    private static final ConfigLoader instance = new ConfigLoader("application.properties");

    public static ConfigLoader getInstance() {
        return instance;
    }
}